Skip to main content

Financial data analysis VII Trends in total repayments under different mortgage amounts

· 2 Minutes to read
Allen Ma

Case (3) Simple financial data analysis

Design a program to compare the trends in the respective total repayments for the same loan amount (e.g. RMB 1 million) but different mortgage (monthly) amounts (calculate at least three mortgage amounts).

# -*- coding: utf-8 -*-
"""
Created on Fri Sept 18 9:50:37 2020

@author: mly
"""
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei'] # Used to display Chinese labels properly

dp_rate = 0.015 # 1-year deposit rate issued by PBoC in October 2015
rates = [0.046, 0.05, 0.054] # 2, 4 and 6 year loan rates
loan_pv = 100 # Unit: million
loan_nper = [2, 4, 6] # Unit: Year
repay_pmt = np.zeros(len(loan_nper)) # Mortgage Monthly Payment Amount
repay_fv = np.zeros(len(loan_nper)) # Actual future final value of repayments
for n in range(len(loan_nper)):
repay_pmt[n] = round(np.pmt(rates[n]/12, loan_nper[n]*12, loan_pv)*10000, 2)
repay_fv[n] = round(np.fv(dp_rate/12, loan_nper[n]*12, repay_pmt[n], 0), 2)

fig, ax = plt.subplots(figsize = (9,6))
ax.plot(loan_nper, np.round(repay_fv/10000, 2), marker= 'o', label = '不同还款年限的按揭终值')
ax.set(xticks = loan_nper, xlabel = '还款年限', ylabel = '100 万按揭终值')
for i in range(len(loan_nper)):
ax.text(loan_nper[i], np.round(repay_fv/10000, 2)[i],
np.round(repay_fv/10000, 2)[i], ha='left', fontsize=20)
ax.legend()
plt.show()

Results of the run.

在这里插入图片描述